﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PropertyManagement.login
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Session["ValidateImage"] != null)
            {
                string str1 = Session["ValidateImage"].ToString();
                //string str1 = Convert.ToString(Session["ValidateImage2"]);
                if (str1.Equals(TextBox3.Text, StringComparison.OrdinalIgnoreCase))
                {
                    string sname, pwd;
                    sname = TextBox1.Text;
                    pwd = TextBox2.Text;

                    string strsql = "select count(*) from suser where sname='" + sname + "' and pwd='" + pwd + "'";

                    mydata myda = new mydata();
                    bool flag = myda.isName(strsql);

                    if (flag)
                    {
                        Session["sname"] = TextBox1.Text;
                        Session["pwd"] = TextBox2.Text;
                        Response.Write("<script language=javascript> alert('登录成功') </script>");
                        Response.Redirect(System.Web.HttpUtility.UrlDecode(Session["url"].ToString()));
                    }
                    else
                    {
                        Response.Write("<script language=javascript> alert('用户名或密码错误') </script>");
                    }
                }
                else
                {
                    TextBox3.Text = "";
                    Response.Write("<script language=javascript> alert('验证码输入错误') </script>");
                }
            }
            else
            {
                Response.Write("<script language=javascript> alert('请输入验证码') </script>");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("../user/addUser.aspx");
        }
    }
}